home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / MC220.ARJ / TYPE4.C < prev    next >
C/C++ Source or Header  |  1992-02-24  |  1KB  |  49 lines

  1. /*
  2.  * Program to display a file assuming tab stops are at 4 character
  3.  * Intervals. By redirecting the output from this program to the
  4.  * printer, you may properly print the MICRO-C listings.
  5.  *
  6.  * In MICRO-C, the operation "a && b" is defined as returning zero
  7.  * without evaluating "b" if "a" evaluates to zero, otherwise "b"
  8.  * is evaluated and returned.
  9.  *
  10.  * The statement "j = (chr != '\n') && j+1" shows how && (or ||) may
  11.  * be used to create a very efficent conditional expression in MICRO-C.
  12.  * NOTE that this is not "standard", and is NOT PORTABLE. The more
  13.  * conventional equivalent is: "j = (chr != '\n') ? j+1 : 0"
  14.  *
  15.  * Copyright 1989,1992 Dave Dunfield
  16.  * All rights reserved.
  17.  */
  18. #include \mc\stdio.h
  19.  
  20. #define TAB_SIZE    4        /* tab spacing */
  21.  
  22. main(argc, argv)
  23.     int argc;
  24.     char *argv[];
  25. {
  26.     int i, j, chr;
  27.     FILE *fp;
  28.  
  29.     if(argc < 2)
  30.         abort("\nUse: type4 <filename*>\n");
  31.  
  32. /* Set output to buffered for higher speed */
  33.     stdout = setbuf(stdout, 512);
  34.  
  35.     for(i=1; i < argc; ++i) {
  36.         if(fp = fopen(argv[i], "rv")) {
  37.             j = 0;
  38.             while((chr = getc(fp)) != EOF) {
  39.                 if(chr == '\t') {            /* tab */
  40.                     do
  41.                         putc(' ', stdout);
  42.                     while(++j % TAB_SIZE); }
  43.                 else {                        /* not a tab */
  44.                     j = (chr != '\n') && j+1;    /* see opening comment */
  45.                     putc(chr, stdout); } }
  46.             fclose(fp); } }
  47.     fflush(stdout);
  48. }
  49.